# -*- coding: utf-8 -*-
# @Time    : 2024/6/24 9:07
# @Author  : floraachy
# @File    : repo_code_commit_detail_page
# @Software: PyCharm
# @Desc:

# 标准库导入
# 第三方库导入
import allure
# 本地应用/模块导入
from utils.base_utils.base_page import BasePage


class RepoCodeCommitDetailPage(BasePage):
    """项目-commit详情页"""
    # 当前节点
    locator_current_commit_id = "//label[text()='当前节点']/following-sibling::span"
    # 复制图标旁的文件名，该定位不具备唯一性，可能存在多个匹配值
    locator_file_name = "//i[@class='iconfont icon-fuzhiicon ml6']/preceding-sibling::span"
    # 查看文件
    locator_read_file_btn = "//span[text()='查看文件']"

    @allure.step("访问commit详情页面：/{repo_owner}/{repo_identifier}/commits/{commit_id}")
    def navigate(self, repo_owner, repo_identifier, commit_id):
        """
        访问commit详情页面
        """
        self.visit(f"/{repo_owner}/{repo_identifier}/commits/{commit_id}")

    @allure.step("获取当前节点的commitId")
    def get_current_commit_id(self):
        """
        获取当前节点的commitId
        """
        return self.get_text(self.locator_current_commit_id)

    @allure.step("获取复制图标旁的文件名称")
    def get_file_name(self):
        """
        获取复制图标旁的文件名称
        """
        return self.get_text(self.locator_file_name)

    @allure.step("点击【查看文件】按钮")
    def click_look_file_button(self):
        """
        点击【查看文件】按钮
        """
        self.click(self.locator_read_file_btn)
